//
//  MWNavigationController.m
//  XiRan-iOS
//
//  Created by Richfit on 2019/10/10.
//  Copyright © 2019 Wood. All rights reserved.
//

#import "MWNavigationController.h"
#import "HSFTabBarController.h"
#import <Masonry/Masonry.h>

@interface MWNavigationController ()

@end

@implementation MWNavigationController

+ (void)initialize {
    [UINavigationBar appearance].barTintColor = MWHexColor(@"#2C3E6C");
    [[UINavigationBar appearance] setTranslucent:NO];
    //    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg"] forBarMetrics:UIBarMetricsDefault];
    [UINavigationBar appearance].titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
    
    UINavigationBarAppearance *navBarAppearance = [UINavigationBarAppearance new];
    navBarAppearance.backgroundColor = MWHexColor(@"#2C3E6C");
    navBarAppearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
    navBarAppearance.shadowColor = [UIColor clearColor];
    navBarAppearance.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
    
    [UINavigationBar appearance].scrollEdgeAppearance = navBarAppearance;
    [UINavigationBar appearance].standardAppearance = navBarAppearance;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        [[MWUserManager manager].tbc.tabBar mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
    }
    [super pushViewController:viewController animated:animated];
}

- (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated{
    UIViewController *vc = [super popViewControllerAnimated:animated];
    
    if (self.childViewControllers.count == 1) {
        [[MWUserManager manager].tbc.tabBar mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo([MWUserManager manager].tbc.tabBarHeight);
        }];
    }
    return vc;
}

- (NSArray<UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
   [[MWUserManager manager].tbc.tabBar mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo([MWUserManager manager].tbc.tabBarHeight);
    }];

    return [super popToRootViewControllerAnimated:animated];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    UIViewController *topVC = self.topViewController;
    return [topVC preferredStatusBarStyle];
}

@end
